//
//  BaseInfoTwoCell.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/3.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "BaseInfoTwoCell.h"
#import "MyInfoModel.h"

@interface BaseInfoTwoCell ()

@property (nonatomic, strong) UILabel *leftLabel;

@property (nonatomic, strong) UIImageView *lineImageView;
@property (nonatomic, strong) UIImageView *rightImageView;

@end

@implementation BaseInfoTwoCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.left.mas_equalTo(self.contentView.mas_left).offset(20);
            make.width.mas_equalTo(80);
        }];
        [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-20);
            make.left.mas_equalTo(self.leftLabel.mas_right);
        }];
        
        [self.lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0.7f);
            make.left.mas_equalTo(self.contentView.mas_left).offset(20);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-20);
            make.bottom.mas_equalTo(self.contentView.mas_bottom);
        }];
        
        [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
            make.size.mas_equalTo(CGSizeMake(18, 18));
        }];
    }
    return self;
}

- (void)updateCellInfoWithModelWithIndexPath:(NSIndexPath *)indexPath baseInfoModel:(MyInfoBasicsModel *)model {
    
    self.rightImageView.hidden = YES;
    [self.rightLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-20);
        make.left.mas_equalTo(self.leftLabel.mas_right);
    }];
    
    if (indexPath.section == 0) {
        self.lineImageView.hidden = NO;
        switch (indexPath.row) {
            case 1:
            {
                self.leftLabel.text = @"姓       名";
                self.rightLabel.text = model.userName;
            }
                break;
            case 2:
            {
                self.leftLabel.text = @"身份证号";
                self.rightLabel.text = model.identityCardNumber;
            }
                break;
            case 3:
            {
                self.leftLabel.text = @"证件地址";
                self.rightLabel.text = model.residenceAddress;
            }
                break;
            case 4:
            {
                self.leftLabel.text = @"有效期限";
                self.rightLabel.text = model.identityCardTerm;
                self.lineImageView.hidden = YES;
            }
                break;
                
            default:
                break;
        }
    }else {
        self.lineImageView.hidden = YES;
        self.leftLabel.text = @"婚姻状态";
        self.rightImageView.hidden = NO;
        self.rightLabel.text = model.maritalValue;

        [self.rightLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-34);
            make.left.mas_equalTo(self.leftLabel.mas_right);
        }];
    }
    
}

- (UILabel *)leftLabel {
    
    if (!_leftLabel) {
        _leftLabel = [[UILabel alloc] init];
        _leftLabel.textColor = HexColor(0x333333);
        _leftLabel.font = [UIFont systemFontOfSize:14];
        
        [self.contentView addSubview:_leftLabel];
    }
    return _leftLabel;
}

- (UILabel *)rightLabel {
    
    if (!_rightLabel) {
        _rightLabel = [[UILabel alloc] init];
        _rightLabel.textColor = HexColor(0x333333);
        _rightLabel.font = [UIFont systemFontOfSize:14];
        [_rightLabel setTextAlignment:NSTextAlignmentRight];
        _rightLabel.numberOfLines = 2;
        
        [self.contentView addSubview:_rightLabel];
    }
    return _rightLabel;
}

- (UIImageView *)lineImageView {
    
    if (!_lineImageView) {
        _lineImageView = [[UIImageView alloc] init];
        _lineImageView.backgroundColor = ThemeMaoLineColor;
        
        [self.contentView addSubview:_lineImageView];
    }
    return _lineImageView;
}

- (UIImageView *)rightImageView {
    
    if (!_rightImageView) {
        _rightImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_chevron_right"]];
        [_rightImageView setContentMode:UIViewContentModeScaleAspectFit];
        
        [self.contentView addSubview:_rightImageView];
    }
    return _rightImageView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
